class User {
    constructor() {
        this.data = [
            {
                id: 1,
                name: 'admin',
                password: '123456'
            }
        ];
    }

    async addUser(username, password) {
        for (let i = 0; i < this.data.length; i++) {
            let item = this.data[i];
            if (item.name == username) {
                return { success: false, msg: '用户已存在' };
            }
        }
        this.data.push({
            id: this.data.length + 1,
            name: username,
            password: password
        });
        return { success: true, msg: '注册成功' };
    }

    async checkPassword(username, password) {
        for (let i = 0; i < this.data.length; i++) {
            let item = this.data[i];
            if (item.name == username && item.password == password) {
                return { success: true, msg: '密码检查成功', data: item };
            }
        }
        return { success: false, msg: '用户名或密码错误' };
    }
}

const user = new User();

module.exports = user;